package com.action.pc.member;

import com.bean.Mb_account;
import com.bean.Sys_user;
import com.common.BaseAction;
import com.github.pagehelper.Page;
import com.service.member.MbAccountService;
import com.service.member.MemberService;
import com.util.Config;
import com.util.StringUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

/**
 * Created by lvjianqing on 2017/9/14.
 */
@Controller
@RequestMapping("member")
public class MemberInfoAction extends BaseAction {
    Logger log = Logger.getLogger(MemberInfoAction.class);
    @Autowired
    private MemberService memberService;
    @Autowired
    private MbAccountService mbAccountService;

    @RequestMapping("list")
    public ModelAndView list(ModelMap modelMap, MemberInfoVo vo) {
        int pageNum = vo.getPageNumInt();
        int pageSize = vo.getPageSizeInt();
        HashMap<String, Object> paraMap = new HashMap<>();
        filterParaMap(paraMap);
        paraMap.put("id", vo.getId());
        paraMap.put("tel", vo.getTel());
        paraMap.put("cardno", vo.getCardno());
        paraMap.put("realname", vo.getRealname());
        paraMap.put("ischeckname", vo.getIscheckname());
        paraMap.put("isactive", vo.getIsactive());
        paraMap.put("ismerchant", vo.getIsmerchant());
        paraMap.put("nickname", vo.getNickname());
        paraMap.put("starttime", vo.getStarttime());
        paraMap.put("endtime", vo.getEndtime());
        Page page = memberService.findMembersByPage(pageNum, pageSize, paraMap);
        HashMap<String, Object> paraMap1 = new HashMap<>();
        paraMap1.put("isactive", 1);
        filterParaMap(paraMap1);
        Page page1 = memberService.findMembersByPage(pageNum, pageSize, paraMap1);
        modelMap.put("actives", page1.getTotal());
        modelMap.put("total", page.getTotal());
        modelMap.put("page", page);
        modelMap.put("pages", page.getPages());
        modelMap.put("pageNum", page.getPageNum());
        modelMap.put("pageSize", page.getPageSize());
        modelMap.put("vo", vo);
        return new ModelAndView("/pc/member_list", modelMap);
    }

    /**
     * 会员账户
     *
     * @param request
     * @param modelMap
     * @param vo
     * @return
     */
    @RequestMapping("account")
    public ModelAndView account(HttpServletRequest request, ModelMap modelMap, MemberInfoVo vo) {
        Integer mid = vo.getId();
        Mb_account account = new Mb_account();
        if (mid != null) {
            account = mbAccountService.selectByMemberId(mid);
        }
        modelMap.put("account", account);
        return new ModelAndView("/pc/member_account", modelMap);
    }
}
